<?php
/**
 * Article
 *
 * Обработка данных статей
 *
 * @author Mike
 */
class Article extends ActiveRecord  {
	protected $tableName = 'article';
	public $pkName = 'ID_article';
	
	protected $arrWysiwyg = array('text');
	protected $arrSettings = array('created_at' => true, 'author' => true, 'updated_at' => true);

	public $validatesLengthOf = array(
			'article_name' => array('min' => 2, 'max' => 256, 'message' => 'Имя - 2-256 символов'),
			'title' => array('min' => 2,'max' => 256, 'message' => 'Title - 2-256 знаков', 'allowNull' => true),
			'description' => array('max' => 512, 'message' => 'Description - не более 512 знаков', 'allowNull' => true),
			'keywords' => array('max' => 256, 'message' => 'Keywords - не более 256 знаков', 'allowNull' => true),
			'title' => array('min' => 2, 'max' => 256, 'message' => 'title - 2 - 256 знаков')
			);

	public $validatesFormatOf = array(
				'url' => array('with' => '/^[\-_a-z0-9\.]+$/ui', 'message' => 'URL заполнен неверно', 'allowNull' => true),
				'essence_type' => array('with' => '#^[123]{1}$#', 'message' => 'Укажите тип страницы'),
	);
	
	public $validatesUniquenessOf = array(
			'url' => array('message' => 'Такой URL уже используется')
	);
  
  public function beforeValidation() {
  	if (!empty($this->tableFields['url'])) {
  		if (in_array($this->tableFields['url'], array('ajax', 'auth', 'parse', 'cms', 'test'))) {
  			$this->errorValidated('url', 'Данный URL нельзя исопльзовать - системный');
  		}
  	}
  }
  
  public function beforeSave() {
  	if(!isset($this->tableFields['no_show_name'])) $this->tableFields['no_show_name'] = 0;
	else $this->tableFields['no_show_name'] = 1;
  }
  
}
?>